
//
// 110722 - AH - (Garage) Created.
// 110727a- AH - Renamed from NoteMark.
// 110727b- AH - Missing java doc.
// 110727c- AH - Finished logic about showing if has note (blue) or not (black)
//               and that do remove note.
// 110804 - AH - (Bybanen *) Moved from package 
//               org.soekrat.gui.swing.chat.objectconversation
// 110805a- AH - Moved private utility method getNoteContent(Node, String) to 
//               new utility class NoteUtil.
// 110805b- AH - Code here replaced with ConcersationComponent.setNote(String).
//

package org.soekrat.gui.swing.chat.objectconversation.note;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JLabel;

import org.soekrat.engine.pit.Node;
import org.soekrat.engine.pit.Pit;
import org.soekrat.gui.swing.chat.objectconversation.ConversationComponent;

/**
 * <p>
 *   {@link JLabel} used to show if a 
 *   {@link Pit} 
 *   {@link Node} has a note content or not and give access to 
 *   {@link NoteDialog} if end user clicks on it. 
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
@SuppressWarnings("serial")
public final class NoteMarkLabel extends JLabel
{
  private final String m_name;
  
  private final ConversationComponent m_cc;
  
  private boolean m_noteExists;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param name       Node name to show note mark for.
   * @param cc         {@link ConversationComponent} {@code this} is created in.
   * @param noteExists {@code true} if not exists.
   */
  public NoteMarkLabel(String name, ConversationComponent cc)
  {
    if (name==null)
    {
      throw new NullPointerException("name");
    }
    if (cc==null)
    {
      throw new NullPointerException("cc");
    }
    
    m_name=name;
    
    m_cc=cc;
    
    Pit pit=cc.getSoekratEngine().getPit();
    m_noteExists=pit.hasNoteContent(name, cc.getOntology());
    
    setNoteTxt();
    
    addMouseListener
    (
      new MouseAdapter()
      {
        public void mouseClicked(MouseEvent e) 
        {
          m_noteExists=m_cc.setNote(m_name);
          setNoteTxt();
        }
      }
    );
    
  }
  
  private void setNoteTxt()
  {
    if (m_noteExists)
    {
      setText("<html> <font color='blue'>#</font></html>");
    }
    else
    {
      setText("<html> <font color='black'>#</font></html>");
    }
  }
  
}
